Skip to content

Instantly share code, notes, and snippets.

@marketinview
Last active July 9, 2020 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marketinview/122ae16c199b320ba1815251aa372c7f to your computer and use it in GitHub Desktop.
Save marketinview/122ae16c199b320ba1815251aa372c7f to your computer and use it in GitHub Desktop.
Excel: Concat vb function to concatenate a range of cells. Note: In newer versions of Excel (e.g. Office 365) the built-in TEXTJOIN feature can be used instead. #excel #vb #concatenate
Function Concat(rng As Range, Optional sep As String = ",") As String
Dim rngCell As Range
Dim strResult As String
For Each rngCell In rng
If rngCell.Value <> "" Then
strResult = strResult & sep & rngCell.Value
End If
Next rngCell
If strResult <> "" Then
strResult = Mid(strResult, Len(sep) + 1)
End If
Concat = strResult
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment